package org.jeecg.modules.lab.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class ReportLoad {

    /**
     * 把签名保存到本地
     *
     * @return
     */
    public String upSignature(String name, String thpt) {
        //图片位置
        String path = "D:\\zhuiExperiment\\picture\\";
        //String imageUrl = "http://11.89.24.203:9008/f/2023-11-30/personsign1701340825442_20231130184026157_20231130184026188_116912.png";
        String filePath = "";
        try {
            URL url = new URL(thpt);
            InputStream inputStream = url.openStream();
            // 创建本地文件路径和文件名
            filePath = path + name + ".jpg";
            // 创建文件输出流
            FileOutputStream outputStream = new FileOutputStream(new File(filePath));
            // 读取输入流中的数据，并写入到输出流中
            byte[] buffer = new byte[1024];
            int bytesRead;
            while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
            // 关闭输入流和输出流
            inputStream.close();
            outputStream.close();
            System.out.println("图片保存成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return filePath;
    }


}

